<?php

namespace app\common\validate\user;

use think\Validate;

class Withdrawal extends Validate
{
    /**
     * 验证规则
     */
    protected $rule = [
        'money' => 'require|checkMoney',
        'account' => 'require',
        'bank_id' => 'require',
        // 'bank' => 'require',
        // 'card_id' => 'require',
        // 'open_bank' => 'require',
        // 'alipay' => 'require',
        // 'mobile' => 'require|regex:1[3-9]\d{9}',
        // 'corporate_name' => 'require',
        // 'corporate_bank' => 'require',
        // 'corporate_open_bank' => 'require',
        // 'corporate_mobile' => 'require|regex:1[3-9]\d{9}',


    ];
    /**
     * 提示消息
     */
    protected $message = [
        'money.require' => '提现金额不能为空',
        'account.require' => '账号不能为空',
        'bank_id.require' => '请选择银行卡',
        // 'open_bank.require' => '开户行不能为空',
        // 'card_id.require' => '身份证不能为空',
        // 'alipay.require' => '支付宝账号不能为空',
        // 'mobile.require' => '联系方式不能为空',
        // 'mobile.regex' => '请填写正确手机号',


    ];
    /**
     * 验证场景
     */
    protected $scene = [
        'wechat' => ['money',  'account'],
        'alipay' => ['money',  'account'],
        'bank' => ['money', 'bank_id'],
    ];

    // 自定义验证规则
    protected function checkMoney($value, $rule, $data)
    {
        $min_money = config('site.min_money');
        if ($value < $min_money) {
            return '最低提现' . $min_money . '元';
        }
        if ($value > $data['commission']) {
            return '佣金不足';
        }
        return true;
    }
}
